package com.group.itms.routes.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.group.itms.routes.R;
import com.group.itms.routes.data.BObject;
import com.group.itms.routes.data.Option;

public class LocationInfoActivity extends BaseActivity implements OnItemClickListener{

	private static final String TAG = "LocationInfoActivity";
	public static final String LOCATION_ID = "location_id";
	
	ArrayAdapter<Option> adapter;
	private BObject mLocation;
	
	public static Intent getIntent(Context c, int objectId) {
		Intent intent = new Intent(c, LocationInfoActivity.class);
		intent.putExtra(OBJECT_ID, objectId);
		return intent;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Bundle args = getIntent().getExtras();
		if (args == null) {
			throw new RuntimeException("LocationInfoActivity does not have aruments");
		}
		int locationId = args.getInt(OBJECT_ID, -1);
		if (locationId == -1) {
			throw new RuntimeException("Missing args with key: " + OBJECT_ID
					+ " to activity: " + getClass());
		}
		mLocation = getObject(locationId);
		if (mLocation == null) {
			throw new RuntimeException("Unable to find Location widh id: "
					+ locationId);
		}
		setTitle(mLocation.getName());
		
		adapter = new ArrayAdapter<Option>(this, R.layout.textview, mLocation.getOptions());
		ListView optionsListView = new ListView(this);
		optionsListView.setOnItemClickListener(this);
		optionsListView.setAdapter(adapter);
		setContentView(optionsListView);
	}

	@Override
	protected String getTag() {
		return TAG;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//	XXX aq locationId da positionId-s araswori tanmimdevrobit awvdidi		
//	XXX	startActivity(InfoDetailActivity.getIntent
//	XXX	(this, adapter.getItem(position).getId(), mLocation.getId()));
//  XXX P.S. option-is magivrad marto mis pozicias gadavcem
		startActivity(InfoDetailActivity.getIntent(this, mLocation.getId(), position), true);
	}
}
